package com.corticon.dialogs.model;

/**
 * @author Lifan Yang
 */

import java.io.Serializable;

import javax.persistence.*;

import org.hibernate.validator.NotEmpty;


@Entity
@Table(name = "ql_locale")
public class Locale extends LookupBase implements Serializable {

    private static final long serialVersionUID = 1L;

    private Country country;
    private Language language;
    private DataValidation dateMask;
    private DataValidation datetimeMask;
    private DataValidation timeMask;

    public Locale() {
    }

    public Locale(Country country, Language language) {
        this.country = country;
        this.language = language;

//        this.id.setCountryId(country.getCode());
//        this.id.setLanguageId(language.getCode());
    }

    /**
     * Create a new Locale and init associations.
     *
     * @return
     */
    public static Locale newInstance() {
        Locale locale = new Locale();
        locale.init();
        return locale;
    }

    /**
     * Init the associations.
     */
    public void init() {
        country = country == null ? new Country() : country;
        language = language == null ? new Language() : language;
        userGroup = userGroup == null ? new UserGroup() : userGroup;
        dateMask = dateMask == null ? new DataValidation() : dateMask;
        datetimeMask = datetimeMask == null ? new DataValidation() : datetimeMask;
        timeMask = timeMask == null ? new DataValidation() : timeMask;
    }

//    @EmbeddedId
//    public LocaleId getId() {
//        return id;
//    }
//
//    public void setId(LocaleId id) {
//        this.id = id;
//    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "countryassoc_code_oid")
    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "languageassoc_code_oid")
    public Language getLanguage() {
        return language;
    }

    public void setLanguage(Language language) {
        this.language = language;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "defdatemaskassoc_code_oid")
    public DataValidation getDateMask() {
        return dateMask;
    }

    public void setDateMask(DataValidation dateMask) {
        this.dateMask = dateMask;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "defdatetimemaskassoc_code_oid")
    public DataValidation getDatetimeMask() {
        return datetimeMask;
    }

    public void setDatetimeMask(DataValidation datetimeMask) {
        this.datetimeMask = datetimeMask;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "deftimemaskassoc_code_oid")
    public DataValidation getTimeMask() {
        return timeMask;
    }

    public void setTimeMask(DataValidation timeMask) {
        this.timeMask = timeMask;
    }
}
